package com.example.netty_pipline.pipeline;

/**
 * ChannelPipeline接口 - 处理器管道
 * 模仿Netty的ChannelPipeline，管理处理器链
 */
public interface ChannelPipeline {
    
    /**
     * 添加处理器到管道头部
     */
    ChannelPipeline addFirst(String name, ChannelHandler handler);
    
    /**
     * 添加处理器到管道尾部
     */
    ChannelPipeline addLast(String name, ChannelHandler handler);
    
    /**
     * 在指定处理器前添加
     */
    ChannelPipeline addBefore(String baseName, String name, ChannelHandler handler);
    
    /**
     * 在指定处理器后添加
     */
    ChannelPipeline addAfter(String baseName, String name, ChannelHandler handler);
    
    /**
     * 移除处理器
     */
    ChannelPipeline remove(String name);
    
    /**
     * 移除处理器
     */
    ChannelPipeline remove(ChannelHandler handler);
    
    /**
     * 获取处理器
     */
    ChannelHandler get(String name);
    
    /**
     * 获取处理器上下文
     */
    ChannelHandlerContext context(String name);
    
    /**
     * 获取处理器上下文
     */
    ChannelHandlerContext context(ChannelHandler handler);
    
    /**
     * 获取管道名称
     */
    String name();
    
    // 入站事件触发方法
    ChannelPipeline fireChannelActive();
    ChannelPipeline fireChannelInactive();
    ChannelPipeline fireChannelRead(Object msg);
    ChannelPipeline fireChannelReadComplete();
    ChannelPipeline fireUserEventTriggered(Object evt);
    ChannelPipeline fireExceptionCaught(Throwable cause);
    
    // 出站操作触发方法
    ChannelPipeline bind(Object localAddress);
    ChannelPipeline connect(Object remoteAddress, Object localAddress);
    ChannelPipeline disconnect();
    ChannelPipeline close();
    ChannelPipeline write(Object msg);
    ChannelPipeline flush();
    ChannelPipeline read();
}